/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package blueprint4j.report;

import java.util.Vector;

public class VectorJRParameter {
	private Vector store=new Vector(),binded = new Vector();

//	public VectorJRParameter(JRParameter field[]) {
//		for (int i =0;i < field.length;i++) {
//			if (!field[i].isSystemDefined()) { 
//				add(field[i]);
//			}
//		}
//	}
//
//	public JRParameter get(int pos){
//		return (JRParameter)store.get(pos);
//	}
//
//	public void add(JRParameter item){
//		store.add(item);
//		binded.add(new Boolean(false));
//	}
//
//	public boolean remove(JRParameter item){
//		binded.remove(store.indexOf(item));
//		return store.remove(item);
//	}
//
//	public JRParameter remove(int pos){
//		binded.remove(pos);
//		return (JRParameter) store.remove(pos);
//	}
//
//	public int size(){
//		return store.size();
//	}
//
//	public void binded(int pos) {
//		binded.set(pos,new Boolean(true));
//	}
//
//	private boolean isBinded(int pos) {
//		return binded.size() > pos && ((Boolean)binded.get(pos)).booleanValue();
//	}
//	
//	public static String getNameFor(BindFieldInterface field) {
//		return field.getBindable().getSourceName() + "__"+field.getName();
//	}
//	
//	private BindFieldInterface find(VectorBindable bindable,JRParameter field)
//	throws BindException {
//		List<String> parameters = new ArrayList<String>();
//		for (int e = 0;e < bindable.size();e++) {
//			for (int p = 0;p < bindable.get(e).getBindFields().length;p++) {
//				parameters.add(getNameFor(bindable.get(e).getBindFields()[p]));
//				if (field.getName().equals(getNameFor(bindable.get(e).getBindFields()[p]))) {
//					return bindable.get(e).getBindFields()[p];
//				}
//			}
//		}
//		if (!field.isForPrompting()) {
//			Log.debug.out("REPORTS PARAMETER MISMATCH","COULD NOT MATCH PARAMETER ["+field.getName()+"] from ["+parameters+"]");
//		}
//		return null;
//		//throw new BindException("COULD NOT LOCATE BIND FIELD FOR JRParameter NAME ["+field.getName()+"]");
//	}
//
//	private BindFieldInterface createBindFieldInterface(JRParameter field,Bindable destination) 
//	throws BindException {
//		if ("java.lang.String".equals(field.getValueClassName())) {
//			return new BindString(field.getName(),field.getDescription(),destination);
//		}
//		if ("java.util.Date".equals(field.getValueClassName())) {
//			return new BindDate(field.getName(),field.getDescription(),destination);
//		}
//		if ("java.sql.Timestamp".equals(field.getValueClassName())) {
//			return new BindDateTime(field.getName(),field.getDescription(),destination);
//		}
//		if ("java.sql.Time".equals(field.getValueClassName())) {
//			return new BindTime(field.getName(),field.getDescription(),destination);
//		}
//		if ("java.lang.Boolean".equals(field.getValueClassName())) {
//			return new BindRealBoolean(field.getName(),field.getDescription(),destination);
//		}
//		throw new BindException("COULD NOT MATCH PROPERTY TYPE ["+field.getValueClassName()+"] TO KNOWN TYPES");
//	}
//	
//	public BindFieldInterface[] getAllNonBindedField(VectorBindable bindable,Bindable destination)
//	throws BindException {
//		VectorBindFieldInterface field = new VectorBindFieldInterface();
//		for (int i = 0;i < size();i++) {
//			if (!((Boolean)binded.get(i)).booleanValue() && get(i).isForPrompting()) {
//				field.add(createBindFieldInterface(get(i),destination));
//			}
//		}
//		return field.toArray();
//	}
//
//	/**
//	 * This converts the basic types to correct type
//	 * converts dates to timestamp exct
//	 */
//	 public static Object correctType(BindFieldInterface field) 
//	 throws BindException {
//		 if (field instanceof BindTime) {
//			 return new java.sql.Time(((java.util.Date)field.getObject()).getTime());  
//		 } else if (field instanceof BindRealBoolean) {
//			 return new Boolean(field.getSerializable());
//		 } else if (field instanceof BindDateTime) {
//			 return new java.sql.Timestamp(((java.util.Date)field.getObject()).getTime());
//		 } else {
//			 return field.getObject();
//		 }
//	 }
//	 
//	/**
//	 * For date, datetime and time field
//	 * expect a java.sql.Timestamp for datetime
//	 * java.sql.time for time
//	 * java.util.date for date
//	 */
//	private void bind(Hashtable map,int pos,Object value) {
//		if ("java.sql.Timestamp".equals(get(pos).getValueClassName())) {
//			map.put(get(pos).getName(),new java.sql.Timestamp(((java.util.Date)value).getTime()));
//		} else if ("java.sql.Time".equals(get(pos).getValueClassName())) {
//			map.put(get(pos).getName(),new java.sql.Time(((java.util.Date)value).getTime()));
//		} else {
//			map.put(get(pos).getName(),value);
//		}
//		binded(pos);
//	}
//	
//	public Hashtable bindMap(VectorBindable bindable)
//	throws BindException {
//		Hashtable map = new Hashtable();
//		for (int i = 0;i < size();i++) {
//			if (!map.containsKey(get(i).getName())) {
//				BindFieldInterface field = find(bindable,get(i));
//				if (field != null) {
//					bind(map,i,field.getObject()); 
//				}
//			}
//		}
//		return map;
//	}
//	
//	public void bindCommon(Hashtable extra) 
//	throws BindException {
//		java.util.Enumeration e = extra.keys();
//		for (;e.hasMoreElements();) {
//			String key = e.nextElement().toString();
//			for (int i =0;i < size();i++) {
//				if (get(i).getName().equals(key)) {
//					if (isBinded(i)) {
//						throw new BindException("CLASHING PARAMETERS. PARAMETER ["+key+"] IS ALREADY BINDED");
//					}
//					bind(extra,i,extra.get(key));
//				}
//			}
//		}
//	}
}

